package com.mgface.framework.utility;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.core.convert.converter.Converter;

public class StringToDateConverter implements Converter<String, Date> {
	private final static Logger log = LogManager.getLogger(StringToDateConverter.class);	
	private String format = "yyyy-MM-dd";

	@Override
	public Date convert(String source) {
		log.info("接收到的日期字符串为:{}",source);
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		try {
			Date date = sdf.parse(source);
			return date;
		} catch (Exception e) {
			log.info("解析接收到的日期字符串发生异常,异常信息为:{}",e.getMessage());
		}
		log.info("解析接收到的日期字符串发生异常,返回当前日期!");
		return new Date();
	}
}
